//
//  JHRegisterViewController.m
//  login
//
//  Created by 蒋梦婷 on 16/9/24.
//  Copyright © 2016年 code. All rights reserved.
//

#import "JHRegisterViewController.h"
#import "JHLoginViewController.h"
#import "UIViewController+MMDrawerController.h"
#import "GHNetWorkTools.h"
#import "SVProgressHUD.h"



@interface JHRegisterViewController ()

@property (weak, nonatomic) IBOutlet UITextField * username; //请输入您的手机号码

@property (weak, nonatomic) IBOutlet UITextField *passWord1;
@property (weak, nonatomic) IBOutlet UITextField *passWord2;
@property (weak, nonatomic) IBOutlet UISegmentedControl *userRight;
@property (weak, nonatomic) IBOutlet UIButton *zhuce;

@property (weak, nonatomic) IBOutlet UIButton *yongHuXieYi;//用户协议按钮

@property (nonatomic ,assign) int code;



@property (nonatomic, assign) BOOL isRight;

@end

@implementation JHRegisterViewController
- (IBAction)clickRegict:(id)sender {
    

    
    if (_passWord1.text == _passWord2.text) {
        NSString *url = @"zhuce";
        
        
        NSDictionary *paramDic = @{@"username":[_username text],@"password":[_passWord1 text],@"role":@"0"};
        
        NSLog(@"username--------:%@",_username.text);
        
        [[GHNetWorkTools sharedTools] GET:url parameters:paramDic progress:^(NSProgress * _Nonnull downloadProgress) {
            NSLog(@"downing--------:");
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            NSLog(@"susses----:%@",responseObject);
            
            NSDictionary *result = [[NSDictionary alloc] init];
            
            if ([responseObject isKindOfClass:[NSData class]]){
                
                result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
                
            }else{
                
                result = responseObject;
            }
            NSLog(@"result----:%@",[result valueForKey:@"msg"]);
            NSInteger code = (NSInteger)[result valueForKey:@"code"];
            if (code == 0) {
                [SVProgressHUD showErrorWithStatus:@"fail"];
            }
            else{
                [SVProgressHUD showSuccessWithStatus:@"susses"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self backToLeftView];
                });
                
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            NSLog(@"fail--------:");
        }];
        
    }
    else{
        
        //tishi
        
    }
    NSLog(@"code--------:%@",self.code);
    if (self.code == 0) {
        //tishi
    }else{
        
        JHLoginViewController *loginVC = [[JHLoginViewController alloc] init];
        [self.navigationController pushViewController:loginVC animated:YES];
    }

}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    
   // [[NSNotificationCenter defaultCenter]postNotificationName:@"haha" object:@"ZVC"];
    
    [self setNav];
    
}

- (void)setNav{
    self.title = @"用户注册";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xianhua"] style:UIBarButtonItemStylePlain target:self action:@selector(backToLeftView)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
    
}

- (void)backToLeftView{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}



#pragma mark -
#pragma mark - 点击 用户协议
- (IBAction)clickYongHuXieYi:(id)sender {
    
    
}


#pragma mark -
#pragma mark - 点击 已有注册用户,直接登录

- (IBAction)clickHaveRegisterAccountBtn:(id)sender {
    
    
    








    JHLoginViewController *loginVC = [[JHLoginViewController alloc] init];
    [self.navigationController pushViewController:loginVC animated:YES];
    
}

@end
